<!DOCTYPE html>  
<html>
<head>  
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" id="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="/static/webAPP/css/reset.css">
<!-- <link rel="stylesheet" href="/static/webAPP/css/ydui.css" type="text/css"/> -->
<title>机器定位</title>  
<style type="text/css">  
html{height:100%}  
body{height:90%;margin:0px;padding:0px} 

/*头部 导航栏*/
.zjzz-buylist-top {
	position: fixed;
	width: 100%;
	height: 45px;
	line-height: 45px;
	z-index: 9999;
	top: 0;
	left: 0;
	color: #333333;
	background: #FFFFFF;
	text-align: center;
	border-bottom: 1px solid #F3F3F3;
}
.zjzz-buylist-t1,
.zjzz-buylist-t2{
	float: left;
}
.zjzz-buylist-t1 {
    width: 30%;
	height: 45px;
	line-height: 45px;
	font-size: 14px;
	background: url(./images/arrow-left.png) no-repeat 10px center;
	background-size: 20%;
}
.zjzz-buylist-t2 {
	width: 40%;
	height: 45px;
	line-height: 45px;
	font-size: 16px;
}


#container{height:76%; width: 100%;margin-top: 45px;}
#container2{
    text-align: center;
    margin-top: 3%;
    width: 100%;
	height: 16%;
	margin-bottom: 6%;
	position: relative;
}
h4{
    text-align: center;
}
.machineplace_btn{
	/* margin-right:5px; */
	background-Color:#FF9201;
	color:#fff;
	border-radius: 5px;
	padding: 5px 8px;
	font-size: 12px;
	position: absolute;
    top: 0px;
    right: 5%;
}
.map-Nav{
	width: 50%;
	height: 40px;
	float: left;
	margin: 5px 0;
}
.map-btn{
	margin: 2px 15%;
	line-height: 36px;
	text-align: center;
	display: inline-block;
	width: 70%;
	height: 36px;
	color: #999;
}
a:link{ text-decoration: none;}
body{background: #F2F0F1;}
.address{
	width: 94%;
	margin-left: 3%;
	float: left;
}
.addressbigbox{
	width: 100%;
	float: left;
}


/* 修改的 */
.adress-box-a{
	background-color: #fff;
	float: left;
	width: 100%;
	margin-top: 10px;
	border-radius: 6px;
}
.adress-box-a-title{
	width: 98%;
	height: 36px;
	line-height: 36px;
	float: left;
	margin-left: 1%;
}
.adress-box-a-title img{
	width: 13px;
	height: 13px;
}
.adress-box-a-title span{
	font-size: 13px;
	color: #999;
}
.addAdress{
	float: right;
}

.adress-box{
	border-bottom: 1px solid #F0F0F0;
	width: 97%;
	float: left;
	margin-left: 3%;
	position: relative;
}
.adress-box1{
	width: 90%;
	height: 100%;
}
.adress-text1{
	font-size: 13px;
	color: #ccc;
	float: left;
	margin: 5px 10px 5px 5px;
}
.text-r{
	float: right;
	color: #FF4E00;
}
.adress-text2{
	width: 85%;
	font-size: 15px;
	font-weight: bold;
	color: #222222;
	float: left;
	margin: 5px 0 10px 10px;
	clear:both
}
.updateAddress{
	height: 100%;
	width: 10%;
	position: absolute;
	top: 0px;
	right: 0;
}
.updateAddress img{
	width: 14px;
	height: 15px;
	margin-top: 34px;
}
.toditu{
	height: 100%;
	width: 16%;
	position: absolute;
	top: 0px;
	right: 0;
}
.toditu img{
	width: 14px;
	height: 15px;
	margin-top: 65px;
	float: left;
}
.adress-box-a-botton{
	width: 100%;
	height: 43px;
	float: left;
	line-height: 43px;
}
.adress-box-a-botton span{
	font-size: 14px;
	margin-left: 10%;
}
.adress-box-a-botton img{
	width: 16px;
	height: 12px;
}
.adress-text3{
	width: 70%;
	font-size: 13px;
	color: #ccc;
	float: left;
	margin: 5px 0 10px 5px;
	clear:both
}
.adress-text2-a{
	width: 60%;
	font-size: 15px;
	font-weight: bold;
	color: #222222;
	float: left;
	margin: 5px 0 10px 5px;
	clear:both
}
.adress-text2-b{
	font-size: 13px;
	color: #ccc;
	margin: 5px 10px 5px 5px;
	width: 30%;
	text-align: right;
}
#addressReceiving{
	position: fixed;
	top: 0;
	left: 0;
	background:rgba(0,0,0,0.5);
	filter:alpha(opacity=50);
	width: 100%;
	height: 100%;
	min-width: 300px;
	display: none;
}
#addressReceiving-box{
	padding-top: 10px;
	width: 90%;
	height: 300px;
	background-color: #fff;
	margin-top: 46%;
	border-radius: 5px;
	margin-left: 5%;
}
#addressReceiving textarea{
	width: 90%;
	margin: 10px 0 0 5%;
	border-radius: 6px;
	text-indent: 5px;
	border: 1px solid #ccc;
}
.updatebtn{
	width: 26%;
	height: 32px;
	border-radius: 16px;
	float: left;
	background-color: #FF970E;
	text-align: center;
	line-height: 32px;
	margin-left: 16%;
	margin-top: 6px;
}
.delAddress-btn{
	display: none;
	width: 90%;
	height: 40px;
	background-color: #ccc;
	float: left;
	text-align: center;
	line-height: 40px;
	margin: 10px 5%;
}
</style>  
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=DouIq9pM7lqTiVOnzOQ6Q8biwgi2GIM0&s=1">
	//v2.0版本的引用方式：src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"
	</script>
<script src="/static/webAPP/js/jquery-1.8.3.min.js"></script>
</head>  
 
<body>
<div class="zjzz-buylist-top">
    <a href="javascript:history.go(-1);" class="zjzz-buylist-t1"></a>
	<span class="zjzz-buylist-t2">机器分布</span>
</div>
<div style="margin-top: 45px;">
	<div class="map-Nav"><a class="map-btn btn2" href="javascript:void(0);">取货点位列表</a></div>
	<div class="map-Nav"><a class="map-btn btn1" href="javascript:void(0);">地图选点收货</a></div>
</div>
<span class="containerInfo" style="display: none;">
	<div id="container"></div>
	<div id="container2">
		<h4>点击选择收货机器</h4>
		<a href="javascript:void(0);" class="machineplace_btn">设为默认</a>
		<span>收货机器:<i id="machineplace"></i></span>
	</div>
</span>

<div class="address">
	<div class="addressbigbox">
				
		<div class="adress-box-a">
			<div class="adress-box-a-title">
				<img src="/static/webAPP/images/wojia.png" alt="">
				<span>我的收货地址</span>
				<a href="javascript:void(0);" class="addAdress">
					<span>新增地址</span>
					<img src="/static/webAPP/images/add.png" alt="">
				</a>
			</div>
			<div class="myadress-info">

				<div class="adress-box">
					<a href="javascript:void(0);" class="adress-box1 adress-box-myaddress">
						<span class="adress-text1 address-txt" style="color:black">送货上门</span>
						<span class="adress-text1 text-r">0km</span>
						<span class="adress-text2 myaddress">正在获取信息</span>
					</a>
					<a href="javascript:void(0);" class="updateAddress">
						<img src="/static/webAPP/images/bianji.png" alt="">
					</a>
				</div>

			</div>
		</div>


		<div class="adress-box-a">
			<div class="adress-box-a-title">
				<img src="/static/webAPP/images/weizhi.png" alt="" style="width: 10px;height: 13px;">
				<span>附近取货机点</span>
			</div>
			<div class="adress-info">
				<div class="adress-box">
					<i style="color: #999;margin-left: 20px;">正在定位信息</i>
				</div>
			</div>
		</div>
   </div>

</div>

<div id="addressReceiving">
	<div id="addressReceiving-box">
		<h4>收货地址</h4>
		<textarea name="" id="S_Address" cols="30" rows="10" placeholder="填写详细地址"></textarea>
		
		<a href="javascript:void(0);" class="delAddress-btn">删除地址</a>
		
		<a href="javascript:void(0);" class="updateAddress-btn1 updatebtn">确定</a>
		<a href="javascript:void(0);" class="updateAddress-btn2 updatebtn">取消</a>
	</div>
	
</div>
<script src="/static/webAPP/lib/mobile/layer.js"></script>
<!-- <script type="text/javascript" src="/static/webAPP/js/ydui.citys.js"></script>
<script type="text/javascript" src="/static/webAPP/js/ydui.js"></script> -->
<!-- <script type="text/javascript">
	/**
 * 默认调用实现地址关联
 */
!function () {
	var $target = $('#J_Address');

	$target.citySelect();

	$target.on('click', function (event) {
		
		event.stopPropagation();
		$target.citySelect('open');
	});

	$target.on('done.ydui.cityselect', function (ret) {
		$(this).val(ret.provance + '省' + ret.city + '' + ret.area);
	});
}();
</script> -->
<script type="text/javascript">
$(function(){
		var user_id = sessionStorage.getItem("sessionUserid")
		$(document).off('click','.adress-box').on('click','.adress-box',function(){
        $(this).siblings(".adress-box-1").slideToggle(300)
	});
	
	// 选择默认地址
	$(document).off('click','.adress-box1').on('click','.adress-box1',function(){
		var default_machine_id = $(this).siblings("a").attr("adressId")
		if (default_machine_id == 1) {
			var addresscontent = '送货上门'
			var addressid =  $(this).siblings("a").attr("addressid")
			var address = $(this).find(".myaddress").text()
			$.ajax({
				type: "post",
									//TODO:
				url: "/app/userInfo/updateAddress",
				data: {address_id: addressid,user_id: user_id},
				dataType: "json",
				success: function(mag){
					sessionStorage.setItem("sessionAddress", address);
				}
			})
		}else{
			var addresscontent = $(this).find(".adress-text2-a").text()
		}
		
		$.ajax({
			type: "post",
								//TODO:
			url: "/app/userInfo/updateDefaultMachine",
			data: {default_machine_id: default_machine_id,user_id: user_id},
			dataType: "json",
			success: function(mag){
				if (mag.success == true) {
					layer.open({
						content: mag.message,
						skin: 'msg',
						time: 3 //2秒后自动关闭
					});
					sessionStorage.setItem("machineplaceId", default_machine_id);
					sessionStorage.setItem("machineplace", addresscontent);
					sessionStorage.setItem("need-refresh", true);
					sessionStorage.setItem("addressid", addressid);
				} else {
					layer.open({
						content: mag.message,
						skin: 'msg',
						time: 3 //2秒后自动关闭
					});
				}
				setTimeout(function(){
					window.history.back(-1);
				}, 1000);
			},
			error:function(){
				layer.open({
					content: '访问失败，请登录重试',
					skin: 'msg',
					time: 3 //2秒后自动关闭
				});
			}
		})
	})

// 地图界面的显示确定按钮
	$(".machineplace_btn").click(function(){
		var default_machine_id = sessionStorage.getItem("machineplaceId")
		var refresh = sessionStorage.getItem("need-refresh")
		if (refresh == '' || refresh == undefined || refresh == null) {
			layer.open({
				content:'未选择机器',
				skin: 'msg',
				time: 3 //2秒后自动关闭
			});
		}else{
			$.ajax({
				type: "post",
									//TODO:
				url: "/app/userInfo/updateDefaultMachine",
				data: {default_machine_id: default_machine_id,user_id: user_id},
				dataType: "json",
				success: function(mag){
					if (mag.success == true) {
						layer.open({
							content: mag.message,
							skin: 'msg',
							time: 3 //2秒后自动关闭
						});
						setTimeout(function(){
							window.history.back(-1);
						}, 1000);
					} else {
						layer.open({
							content: mag.message,
							skin: 'msg',
							time: 3 //2秒后自动关闭
						});
					}
				},
				error:function(){
					layer.open({
						content: '检查是否登录',
						skin: 'msg',
						time: 3 //2秒后自动关闭
					});
				}
			})
		}
	})

	$(document).off('click','.updateAddress').on('click','.updateAddress',function(){
		$("#addressReceiving").show()
		var addressId = $(this).attr("addressid")
		// console.log($(this).siblings("a").children(".myaddress").html())
		 var myaddressinfo = $(this).siblings("a").children(".myaddress")
		 $(".delAddress-btn").show()
		 $("#S_Address").val(myaddressinfo.html())

		// 确定修改地址
		$(".updateAddress-btn1").off('click').on('click',function(){
			var address = $("#S_Address").val()
			if (address == '') {
				layer.open({
					content: '填写位置信息',
					skin: 'msg',
					time: 3 //2秒后自动关闭
				});
			}else{
				$.ajax({
					type: "post",
										//TODO:
					url: "/app/userInfo/updateDeliveryAddress",
					data: {address : address,addressId: addressId,user_id: user_id},
					dataType: "json",
					success: function(mag){
						myaddressinfo.html(address)
						$("#addressReceiving").hide()
						$("#S_Address").val('')
					}
				})
			}
			
		})

		// 删除地址
		$(document).off('click','.delAddress-btn').on('click','.delAddress-btn',function(){
			$.ajax({
				type: "post",
									//TODO:
				url: "/app/userInfo/deleteDeliveryAddress",
				data: {addressId: addressId,user_id: user_id},
				dataType: "json",
				success: function(mag){
						window.location.reload();
					$("#addressReceiving").hide()
					$("#S_Address").val('')
				}
			})
		})

		// 取消修改
		$(".updateAddress-btn2").off('click').on('click',function(){
			$("#S_Address").val('')
			$("#addressReceiving").hide()
		})
	})

	// 新增收货地址
	$(".addAdress").off('click').on('click',function(){
		$("#addressReceiving").show()
		$(".delAddress-btn").hide()


		$(".updateAddress-btn1").off('click').on('click',function(){
			var address = $("#S_Address").val()
			if (address == '') {
				layer.open({
					content: '填写位置信息',
					skin: 'msg',
					time: 3 //2秒后自动关闭
				});
			}else{
				$.ajax({
					type: "post",
										//TODO:
					url: "/app/userInfo/addDeliveryAddress",
					data: {address : address,user_id: user_id},
					dataType: "json",
					success: function(mag){
						window.location.reload();
						$("#addressReceiving").hide()
						$("#S_Address").val('')
					}
				})
			}
			
		})
		// 取消修改
		$(".updateAddress-btn2").off('click').on('click',function(){
			$("#S_Address").val('')
			$("#addressReceiving").hide()
		})
	})
	

// 加载地址信息
	var userName = sessionStorage.getItem("sessionName")
	var useraddress = sessionStorage.getItem("sessionAddress")
	var machineplaceId = sessionStorage.getItem("machineplaceId")
	if (useraddress == null || useraddress == '' || useraddress == undefined) {
		$(".myaddress").html("登录超时，请重新登录")
	}else{
		$(".myaddress").html(useraddress)
	}

	var addressid = sessionStorage.getItem("addressid")
	if(addressid == null){
		var addressid = 0
	}

	var address = ''
	$.ajax({
		type: "post",
							//TODO:
		url: "/app/userInfo/queryDeliveryAddress",
		data: {user_id: user_id},
		dataType: "json",
		success: function(mag){
			if (mag.data == '') {
				address = '<div class="adress-box"><span class="adress-text1 address-txt" style="color:black">送货上门</span><span class="adress-text1 text-r">0km</span><span class="adress-text2 myaddress">没有收货地址</span></div>'
			$(".myadress-info").html(address)
			}else{
				if (mag.data.length <= 2) {
					for (let i = 0; i < mag.data.length; i++) {
						if (addressid == mag.data[i].id) {
							var address1 = '<div class="adress-box" style="background-color: #FFF9F0;"><a href="javascript:void(0);" class="adress-box1 adress-box-myaddress"><span class="adress-text1 address-txt" style="color:black">送货上门</span><span class="adress-text1 text-r">0km</span><span class="adress-text2 myaddress">'+ mag.data[i].address +'</span></a><a href="javascript:void(0);" adressId="1" addressid="'+ mag.data[i].id +'" class="updateAddress"><img src="/static/webAPP/images/bianji.png" alt=""></a></div>'
						}else{
							var address1 = '<div class="adress-box"><a href="javascript:void(0);" class="adress-box1 adress-box-myaddress"><span class="adress-text1 address-txt" style="color:black">送货上门</span><span class="adress-text1 text-r">0km</span><span class="adress-text2 myaddress">'+ mag.data[i].address +'</span></a><a href="javascript:void(0);" adressId="1" addressid="'+ mag.data[i].id +'" class="updateAddress"><img src="/static/webAPP/images/bianji.png" alt=""></a></div>'
						}
						
						address += address1
					}
				$(".myadress-info").html(address)
				}else{
					for (let i = 0; i < 2; i++) {
						if (addressid == mag.data[i].id) {
							var address1 = '<div class="adress-box" style="background-color: #FFF9F0;"><a href="javascript:void(0);" class="adress-box1 adress-box-myaddress"><span class="adress-text1 address-txt" style="color:black">送货上门</span><span class="adress-text1 text-r">0km</span><span class="adress-text2 myaddress">'+ mag.data[i].address +'</span></a><a href="javascript:void(0);" adressId="1" addressid="'+ mag.data[i].id +'" class="updateAddress"><img src="/static/webAPP/images/bianji.png" alt=""></a></div>'
						}else{
							var address1 = '<div class="adress-box"><a href="javascript:void(0);" class="adress-box1 adress-box-myaddress"><span class="adress-text1 address-txt" style="color:black">送货上门</span><span class="adress-text1 text-r">0km</span><span class="adress-text2 myaddress">'+ mag.data[i].address +'</span></a><a href="javascript:void(0);" adressId="1" addressid="'+ mag.data[i].id +'" class="updateAddress"><img src="/static/webAPP/images/bianji.png" alt=""></a></div>'
						}
						address += address1
					}
				$(".myadress-info").html(address + '<a href="javascript:void(0);" class="adress-box-a-botton"><span>展开全部地址</span><img src="/static/webAPP/images/arrow-bottom2.png" alt=""></a>')
				}
			}
		}
	})
	$(document).off('click','.adress-box-a-botton').on('click','.adress-box-a-botton',function(){
		$.ajax({
			type: "post",
								//TODO:
			url: "/app/userInfo/queryDeliveryAddress",
			data: {user_id: user_id},
			dataType: "json",
			success: function(mag){
				for (let i = 2; i < mag.data.length; i++) {
					if (addressid == mag.data[i].id) {
							var address2 = '<div class="adress-box" style="background-color: #FFF9F0;"><a href="javascript:void(0);" class="adress-box1 adress-box-myaddress"><span class="adress-text1 address-txt" style="color:black">送货上门</span><span class="adress-text1 text-r">0km</span><span class="adress-text2 myaddress">'+ mag.data[i].address +'</span></a><a href="javascript:void(0);" adressId="1" addressid="'+ mag.data[i].id +'" class="updateAddress"><img src="/static/webAPP/images/bianji.png" alt=""></a></div>'
						}else{
							var address2 = '<div class="adress-box"><a href="javascript:void(0);" class="adress-box1 adress-box-myaddress"><span class="adress-text1 address-txt" style="color:black">送货上门</span><span class="adress-text1 text-r">0km</span><span class="adress-text2 myaddress">'+ mag.data[i].address +'</span></a><a href="javascript:void(0);" adressId="1" addressid="'+ mag.data[i].id +'" class="updateAddress"><img src="/static/webAPP/images/bianji.png" alt=""></a></div>'
						}
					address += address2
				}
				$(".myadress-info").html(address)
			}
		})
	})
	



	//导航栏的切换
	$(".btn2").css({"border-bottom":"5px solid #FF9201","color":"#FF9201"})
	$(".btn1").click(function(){
		$(".containerInfo").show()
		$(".address").hide()
		$(this).css({"border-bottom":"5px solid #FF9201","color":"#FF9201"})
		$(".btn2").css({"border-bottom":"","color":"#999"})
	})
	$(".btn2").click(function(){
		$(".containerInfo").hide()
		$(".address").show()
		$(this).css({"border-bottom":"5px solid #FF9201","color":"#FF9201"})
		$(".btn1").css({"border-bottom":"","color":"#999"})
	})


	
})
// 百度地图API功能	
	var map = new BMap.Map("container");
	map.centerAndZoom(new BMap.Point(117.14860866,31.78095688), 15);
	
	var opts = {
		width : 250,     // 信息窗口宽度
		height: 80,     // 信息窗口高度
		title : "机器位置信息" , // 信息窗口标题
		enableMessage:true//设置允许信息窗发送短息
	};

// TODO:添加的点击事件,索引到地图显示的指定位置
$(document).on('click','.toditu',function(){
		$(".containerInfo").show()
		$(".address").hide()
		$(".btn1").css({"border-bottom":"5px solid #FF9201","color":"#FF9201"})
		$(".btn2").css({"border-bottom":"","color":"#999"})
		$(this).attr("adressLng")
		var lng1 = $(this).closest(".toditu").attr("adressLng")
		var lat1 = $(this).closest(".toditu").attr("adressLat")
		setTimeout(function(){
			var point1 = new BMap.Point(lng1,lat1);
			map.centerAndZoom(point1,15);
		}, 500);
	})

	var tag = ''
	$.ajax({
		type: "get",
							//TODO:
		url: "/app/machineInfo/queryMachineList",
		data: '',
		dataType: "json",
		success: function(mag){
			for(var i=1;i<mag.data.length;i++){
				var marker = new BMap.Marker(new BMap.Point(mag.data[i].longitude,mag.data[i].latitude));  // 创建标注点
				var content = mag.data[i].place;
				var type = mag.data[i].type;
				var capacity = mag.data[i].capacity;
				// marker.setAnimation(BMAP_ANIMATION_BOUNCE);//标注添加动画效果
				marker.customData = mag.data[i].id
				map.addOverlay(marker);
				addClickHandler(content,marker,type,capacity);
			}
		},
		error: function(){
			layer.open({
				content: '列表加载失败,请检查网络和定位',
				skin: 'msg',
				time: 3 //2秒后自动关闭
			});
		}
	})
    //添加控件
    map.enableScrollWheelZoom(true);
	var ctrlNav = new window.BMap.NavigationControl({
		anchor: BMAP_ANCHOR_TOP_LEFT,
		type: BMAP_NAVIGATION_CONTROL_LARGE
	});
	map.addControl(ctrlNav);
	map.addControl(new BMap.GeolocationControl());
	
//实现定位，计算出每个点位到定位的距离
var default_machine_id = sessionStorage.getItem("machineplaceId")
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
	if(this.getStatus() == BMAP_STATUS_SUCCESS){
		// var myIcon = new BMap.Icon("/images/personaldingwei.png", new BMap.Size(23, 25))
		var mk = new BMap.Marker(r.point);
		map.addOverlay(mk);
		map.panTo(r.point);
		var arr = []
		$.ajax({
			type: "get",
								//TODO:
			url: "/app/machineInfo/queryMachineList",
			data: '',
			dataType: "json",
			success: function(mag){
				let Longitude = r.point.lng; //获取用户的经度
				let Latitude = r.point.lat; //获取用户的纬度	
				let pointA = new BMap.Point(Longitude, Latitude); //用户的经纬度
				for (var i=1;i<mag.data.length;i++) {
					let pointB = new BMap.Point(mag.data[i].longitude, mag.data[i].latitude); //从数据库中取出商家的经纬度
					const distance = ((map.getDistance(pointA, pointB)) / 1000).toFixed(1)
					var arr1 = {place: mag.data[i].place,distance: distance,adressLng:mag.data[i].longitude,adressLat:mag.data[i].latitude,id:mag.data[i].id,place_address: mag.data[i].place_address,type: mag.data[i].type,capacity: mag.data[i].capacity}
					
					arr.push(arr1)
				}
				// 根据定位计算，按距离排列并附带相应的信息参数
				var placearray = arr.sort(compare("distance"))
				// 数组排序，形成新的数组
				for (let j = 0; j < placearray.length; j++) {
					if (default_machine_id != null && default_machine_id != undefined) {
						if (placearray[j].id == default_machine_id) {
							var tag1 = '<div class="adress-box" style="background-color: #FFF9F0;"><a href="javascript:void(0);" class="adress-box1"><span class="adress-text1" style="color:black">'+ typefun(placearray[j].type) +'</span><span class="adress-text1 text-r">'+ placearray[j].distance +'km</span><span class="adress-text2-a">'+ placearray[j].place +'</span><span class="adress-text2-b text-r">剩余空位：'+ capacityInfo(placearray[j].capacity) +'</span><span class="adress-text3">'+ placearray[j].place_address +'</span></a><a href="javascript:void(0);" adressLng="'+ placearray[j].adressLng +'" adressLat="'+ placearray[j].adressLat +'" adressId="'+ placearray[j].id +'"  class="toditu"><span style="font-size:10px;float:left;margin-top: 65px;width: 50%;color:#ccc;">位置</span><img src="/static/webAPP/images/ditu.png" alt=""></a></div>'
						}else{
							var tag1 = '<div class="adress-box"><a href="javascript:void(0);" class="adress-box1"><span class="adress-text1" style="color:black">'+ typefun(placearray[j].type) +'</span><span class="adress-text1 text-r">'+ placearray[j].distance +'km</span><span class="adress-text2-a">'+ placearray[j].place +'</span><span class="adress-text2-b text-r">剩余空位：'+ capacityInfo(placearray[j].capacity) +'</span><span class="adress-text3">'+ placearray[j].place_address +'</span></a><a href="javascript:void(0);" adressLng="'+ placearray[j].adressLng +'" adressLat="'+ placearray[j].adressLat +'" adressId="'+ placearray[j].id +'"  class="toditu"><span style="font-size:10px;float:left;margin-top: 65px;width: 50%;color:#ccc;">位置</span><img src="/static/webAPP/images/ditu.png" alt=""></a></div>'
						}
					}else{
						var tag1 = '<div class="adress-box"><a href="javascript:void(0);" class="adress-box1"><span class="adress-text1" style="color:black">'+ typefun(placearray[j].type) +'</span><span class="adress-text1 text-r">'+ placearray[j].distance +'km</span><span class="adress-text2-a">'+ placearray[j].place +'</span><span class="adress-text2-b text-r">剩余空位：'+ capacityInfo(placearray[j].capacity) +'</span><span class="adress-text3">'+ placearray[j].place_address +'</span></a><a href="javascript:void(0);" adressLng="'+ placearray[j].adressLng +'" adressLat="'+ placearray[j].adressLat +'" adressId="'+ placearray[j].id +'"  class="toditu"><span style="font-size:10px;float:left;margin-top: 65px;width: 50%;color:#ccc;">位置</span><img src="/static/webAPP/images/ditu.png" alt=""></a></div>'
					}
					tag += tag1
				}
				
				
				$(".adress-info").html(tag)
			}
		})
		
	}
	else {
		alert('failed'+this.getStatus());
		layer.open({
			content: '定位失败,请打开定位',
			skin: 'msg',
			time: 3 //2秒后自动关闭
		});
	}        
},{enableHighAccuracy: true})
    
	function addClickHandler(content,marker,type,capacity){
		//标注点监听事件
		marker.addEventListener("click",function(e){
			openInfo(content,e)
			$.ajax({
				url:'https://api.map.baidu.com/geocoder/v2/?ak=Ya2nSaqjT3vNrIgba1v4nfWzSxGdtgZD&location=' + e.target.point.lat + ',' + e.target.point.lng + '&output=json&pois=1&s=1',
				dataType: "jsonp",
				callback: 'BMap._rd._cbk43398',
				success: function(mag){
					var city = mag.result.addressComponent.city
					var citycode = mag.result.cityCode
					sessionStorage.setItem("citycode", citycode);
					sessionStorage.setItem("city", city);
				}
			})
			sessionStorage.setItem("machineplaceId", marker.customData);
			sessionStorage.setItem("machineplace", content);
			sessionStorage.setItem("need-refresh", true);
			$("#machineplace").html(content)
			if (type == 0) {
				$("#machineplace").html(content + '(收货柜)<br>可用空位<span style="color:#379EDE">' + capacity + '</span>')
				layer.open({
					content: '已选择机器收货',
					skin: 'msg',
					time: 2 //2秒后自动关闭
				});
			}else if (type == 1) {
				$("#machineplace").html(content + '(门店)')
				layer.open({
					content: '已选择门店收货',
					skin: 'msg',
					time: 2 //2秒后自动关闭
				});
			}else{
				$("#machineplace").html(content)
				layer.open({
					content: '已选择该地址',
					skin: 'msg',
					time: 2 //2秒后自动关闭
				});
			}
		});
	}
	function compare(property) {
		return function (a, b) {
			var value1 = a[property];
			var value2 = b[property];
			return value1 - value2;
		}
	}
	function openInfo(content,e){
		var p = e.target;
		var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
		var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象 
		map.openInfoWindow(infoWindow,point); //开启信息窗口
	}
	function typefun(param) {
		if (param == 0) {
			var type ='售货机'
		}else if(param == 1){
			var type ='门店'
		}else{
			var type ='未定义类型'
		}
		return type
	}
	function capacityInfo(params) {
		if (params == null || params == undefined) {
			var params = ''
		}
		return params
	}
</script>  
</body>  
</html>